package com.awifi.demo.controller;

import com.alibaba.fastjson.JSON;
import com.awifi.demo.dao.TeacherMapper;
import com.awifi.demo.entity.Teacher;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.server.Session;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;

/**
 * @description: ToDo
 * @author: marin
 * @time: 2020/8/24 15:59
 */

@Slf4j
@RestController
@RequestMapping("/teacher")
public class TeacherController {

    public static HashMap<String,String> codeMaps = new HashMap<String,String>(){
        {
            put("name","tony");
            put("age","12");
        }

    };

    @Autowired
    private TeacherMapper teacherMapper;

    @GetMapping("/list")
    public String getString(String name, HttpServletResponse response) throws UnsupportedEncodingException {
        response.setCharacterEncoding("gb2312");
        Teacher teacherById = teacherMapper.findTeacherById(1);
        Cookie cookie = new Cookie("teacher", URLEncoder.encode(teacherById.getName(),"utf-8"));
        Cookie cookie1 = new Cookie("name",URLEncoder.encode("123","utf-8"));
        response.addCookie(cookie);
        response.addCookie(cookie1);
        System.out.println(teacherById);
        return JSON.toJSONString(teacherById);
    }


}
